home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 019 / blackjack / bj.c next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  91 lines

  1. /* BJ.C        Blackjack
  2.  */
  3.  
  4. #include "local.h"
  5. #include "bj.h"
  6. #include "dekmgr.h"
  7. #include "hndmgr.h"
  8. #include "ttymgr.h"
  9.  
  10. main()
  11. {
  12.    CASH  action;     /* how much money has crossed the table */
  13.    CASH  bet;        /* amount of player's current bet per hand */
  14.    CASH  result;     /* net result of this hand, plus or minus */
  15.    CASH  standing;   /* how much has player won or lost */
  16.    bool  canhit;     /* can player's hand take a hit? */
  17.    bool  isdbl;      /* did player take DBLDN? */
  18.    bool  isinsur;    /* did player take insurance? */
  19.    short hand;       /* current hand number */
  20.    short reply;      /* player's reply to DBLDN, SPLIT */
  21.    short tophand;    /* how many hands is player playing, 1 or 2 */
  22.  
  23.    void  opndek(), shuffl(), deal(), show();
  24.    CASH  getbet(), outcom();
  25.    bool  deklow(), hit(), takes(), allbst();
  26.    short val(), query(), split(), score();
  27.  
  28. #ifdef AMIGA    /* Braindamaged Lattice C has no default ^C checking */
  29.    extern int Enable_Abort;
  30.    Enable_Abort = 1;
  31. #endif
  32.  
  33.    printf("Copyright (C) Plum Hall Inc., 1983\n");
  34.    /* permission to copy and modify is granted, provided that this
  35.     * printout and comment remain intact.
  36.     */
  37.    printf("\nWelcome to the Blackjack table\n");
  38.    action = standing = 0;
  39.    opndek();
  40.    while ((bet = getbet()) != 0) {
  41.       tophand = 1;
  42.       isinsur = isdbl = NO;
  43.       if (deklow())
  44.          shuffl();
  45.       deal();
  46.       if (val(DEALER, 0) == 11)
  47.          isinsur = takes("i");
  48.       reply = query();
  49.       if (reply == SPLIT)
  50.          tophand = split();
  51.       else if (reply == DBLDN) {
  52.          hit(1);
  53.          printf("\n");
  54.          isdbl = YES;
  55.          bet *= 2;
  56.       }
  57.       for (hand = 1; hand <= tophand; ++hand) {
  58.          if (tophand == 2)
  59.             printf("Hand %d:\n", hand);
  60.          canhit = !isdbl;
  61.          canhit &= !isbj(1);
  62.          canhit &= (reply != SPLIT || val(1, 0) != 11);
  63.          while (canhit && takes("h")) {
  64.             canhit = hit(hand);
  65.             printf("\n");
  66.          }
  67.          if (21 < score(hand))
  68.             printf("Bust\n");
  69.       }
  70.       printf("Dealer has ");
  71.       show(DEALER, 0);
  72.       printf(" + ");
  73.       show(DEALER, 1);
  74.       if (!allbst())
  75.          while (score(DEALER) < 17)
  76.             hit(DEALER);
  77.       printf(" = %d\n", score(DEALER));
  78.       result = outcom(bet, tophand, isinsur, isdbl);
  79.       action += ABS(result);
  80.       standing += result;
  81.       printf("action= ");
  82.       printf(CASHOUT, action);
  83.       printf(" standing = ");
  84.       printf(CASHOUT, standing);
  85.       printf("\n");
  86.    }
  87.    printf("\nThanks for the game.\n");
  88.    exit(SUCCEED);
  89. }
  90.  
  91.